package com.situ.mall.admin.interceptor;

import com.situ.mall.admin.util.RequestUtil;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        Object o = RequestUtil.getCurrent();

        if(o == null){
            //不是ajax就重定向
            response.sendRedirect("/login");
            //是ajax就返回401错误码
            return  false;
        }else{

            return true;
        }

    }
}
